﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TCM.DbContextt;
using TCM.Models;
using System.Data.Entity;

namespace TCM.Forms
{
    public partial class UserManager : Form
    {

        private BaseContext db;
        public UserManager()
        {
            InitializeComponent();
            db = new BaseContext();
            db.Users.Load();

            dataGridView1.DataSource = db.Users.Local.ToBindingList();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UserCreator userCreator = new UserCreator();
            var result = userCreator.ShowDialog(this);

            if (result == DialogResult.Cancel)
                return;

            User user = new User();

            user.UserId = Guid.NewGuid();
            user.Account = userCreator.textBox1.Text;
            user.Password = userCreator.textBox2.Text;
            //user.RoleId = (Guid)userCreator.comboBox1.SelectedValue;

            db.Users.Add(user);
            db.SaveChanges();
        }
    }
}
